package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.student.domain.Student;
import com.ruoyi.student.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Anonymous
@RestController
@Api(tags = "学生管理")
public class StudentController {

    @Autowired
    private StudentService service;

    @ApiOperation(value = "获取所有学生列表")
    @RequestMapping("/GetStudentAll")
    public AjaxResult GetStudentAll(){
        List<Student> result = service.getStudentList();
        return AjaxResult.success(result);
    }
    @ApiOperation("新增学生")
    @PostMapping("/AddStudent")
    public AjaxResult addStudent(@RequestBody Student student){
        int result = service.addStudent(student);
        return AjaxResult.success(result);
    }

//    根据学生姓名查询
    @ApiOperation("根据姓名查询学生")
//    比较复杂的查询用post，通常用get
    @PostMapping("/GetStudentByName")
    public AjaxResult GetStudentByName(String sname){
       return AjaxResult.success(service.queryStudentByName(sname));
    }
    @ApiOperation("修改学生")
    @PostMapping("/ModifyStudent")
    public AjaxResult ModifyStudent( @RequestBody Student student){
        service.updateStudent(student);
        return AjaxResult.success();
    }
    @ApiOperation("删除学生信息")
    @GetMapping("/DeleteStudent")
    public AjaxResult DeleteStudent( int id){
        service.deleteStudent(id);
        return AjaxResult.success();
    }
}
